<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
    <xsl:template match="/trip">
        <kml xmlns="http://earth.google.com/kml/2.1">
            <Document>
                <name>tracks.kml</name>
                <Style id="line">
                    <LineStyle>
                        <color>ff0000ff</color>
                        <width>1.5</width>
                    </LineStyle>
                </Style>
                <xsl:for-each select="fotos/foto">
                    <xsl:variable name="foto" select="@src"/>
                    <Style id="foto_{$foto}">
                        <IconStyle>
                            <scale>1.5</scale>
                            <Icon>
                                <href>
                                    <xsl:value-of select="@src"/>
                                </href>
                            </Icon>
                        </IconStyle>
                    </Style>
                </xsl:for-each>
                <Folder>
                    <name>Fotos</name>
                    <open>1</open>
                    <xsl:for-each select="fotos/foto">
                        <xsl:variable name="foto" select="@src"/>
                        <Placemark>
                            <name>
                                <xsl:value-of select="@src"/>
                            </name>
                            <styleUrl>#foto_<xsl:value-of select="@src"/></styleUrl>
                            <description>
                                <img src="{$foto}"/>
                                <p><xsl:value-of select="@date"/></p>
                            </description>
                            <Point>
                                <coordinates><xsl:value-of select="lon"/>,<xsl:value-of select="lat"
                                    /></coordinates>
                            </Point>
                        </Placemark>
                    </xsl:for-each>
                </Folder>
                <Folder>
                    <name>Tracks</name>
                    <open>1</open>
                    <xsl:for-each select="tracks/track">
                        <Placemark>
                            <name>
                                <xsl:value-of select="@start"/>
                            </name>
                            <styleUrl>#line</styleUrl>
                            <LineString>
                                <coordinates>
                                    <xsl:for-each select="point">
                                        <xsl:value-of select="lon"/>,<xsl:value-of select="lat"
                                        /><xsl:text> </xsl:text>
                                    </xsl:for-each>
                                </coordinates>
                            </LineString>
                        </Placemark>
                    </xsl:for-each>
                </Folder>
            </Document>
        </kml>
    </xsl:template>
</xsl:stylesheet>
